//
//  MyLifeViewController.m
//  ForengnMenu
//
//  Created by @-@ on 16/1/14.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "MyLifeViewController.h"
#import "MyLifeTableViewCell.h"
#import "MyLifeDetailsViewController.h"

@interface MyLifeViewController ()<UITableViewDataSource,UITableViewDelegate,MyTableViewCellDelegate,UIGestureRecognizerDelegate>


@property NSArray * headViews;

@property NSArray * middleViews;

@property NSArray * middleView2s;

@property NSArray * zanButtons;

@property NSArray * commentViews;

@property NSArray * zanView2s;

@property NSArray * browseViews;

@property NSArray * nameLabels;

@property NSArray * timeLabels;

@property NSArray * contentLabels;

@property NSMutableArray * zanLabels;

@property NSArray * commentLabels;

@property NSArray * zanLabel2s;

@property NSArray * browseLabels;

@property NSArray * zanLabel3s;
@property (weak, nonatomic) IBOutlet UITableView *myTabelView;

@property UIView * tapView;

@property UIView * tapView2;

@property BOOL iszan;

@property CGFloat  lastScale;


@end

@implementation MyLifeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //修改返回按钮的字
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];
    
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"headImage.jpg"] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 30, 30);
    button.layer.cornerRadius = button.frame.size.height/2.0f;
    button.layer.masksToBounds = YES;
    
    [button addTarget:self action:@selector(headAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    UIButton * rightBnt = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBnt setImage:[UIImage imageNamed:@"TellAbout"] forState:UIControlStateNormal];
    rightBnt.frame = CGRectMake(0, 0, 30, 30);
    
    [rightBnt addTarget:self action:@selector(tellAboutAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBnt];

    
    self.headViews=@[@"tuxiang1@2x.jpg",@"tuxiang4@2x.jpg"];
    
    self.middleViews=@[@"makalong@2x.jpg",@"applepie@2x.jpg"];
    
    self.middleView2s=@[@"xiangjian@2x.jpg",@"yidalimian@2x.jpg"];
    
    self.zanButtons=@[@"iconfont-zanzan.png",@"iconfont-zanzan.png"];
    
    self.commentViews=@[@"iconfont-pinglun@2x.png",@"iconfont-pinglun@2x.png"];
    
    self.zanView2s=@[@"iconfont-zan.png",@"iconfont-zan.png"];
    
    self.browseViews=@[@"iconfont-liulan@2x.png",@"iconfont-liulan@2x.png"];
    
    self.nameLabels=@[@"甘甜的苦涩",@"苦涩的甘甜"];
    
    self.timeLabels=@[@"今天8:34",@"今天8:50"];
    
    self.contentLabels=@[@"感觉今天过的很好,了解了很多美食,味道都很不错,有时间小伙伴可以一起去尝尝。",@"这个菜很爽口,味道也相当好。"];
    
    self.zanLabels=[NSMutableArray arrayWithArray:@[@"20",@"30"]];
    
    
    
    self.commentLabels=@[@"24",@"29"];
    
    self.zanLabel2s=@[@"苦涩的甘甜,匆匆那年,一只小萌兽,对你爱不完,漫长的岁月,花濑LOVE邪",@"甘甜的苦涩,人见人爱,花间花开,给我一个世界,iPhone 6热卖,请叫我雷锋"];
    
    self.browseLabels=@[@"浏览220次",@"浏览100次"];
    
    self.zanLabel3s=@[@"等人觉得很赞",@"等人觉得很赞"];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * identifier=@"cell";
    
    MyLifeTableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:identifier];
    
    cell.headView.image=[UIImage imageNamed:self.headViews[indexPath.section]];
    
    cell.middleView.image=[UIImage imageNamed:self.middleViews[indexPath.section]];
    
    cell.middleView2.image=[UIImage imageNamed:self.middleView2s[indexPath.section]];
    
    
    
    cell.commentView.image=[UIImage imageNamed:self.commentViews[indexPath.section]];
    
    cell.zanView2.image=[UIImage imageNamed:self.zanView2s[indexPath.section]];
    
    cell.browseView.image=[UIImage imageNamed:self.browseViews[indexPath.section]];
    
    cell.nameLabel.text=self.nameLabels[indexPath.section];
    
    cell.timeLabel.text=self.timeLabels[indexPath.section];
    
    cell.contentLabel.text=self.contentLabels[indexPath.section];
    
    cell.zanLabel.text=self.zanLabels[indexPath.section];
    
    cell.commentLabel.text=self.commentLabels[indexPath.section];
    
    cell.zanLabel2.text=self.zanLabel2s[indexPath.section];
    
    cell.browseLabel.text=self.browseLabels[indexPath.section];
    
    cell.zanLabel3.text=self.zanLabel3s[indexPath.section];
    
    
    tableView.separatorStyle=UITableViewCellAccessoryNone;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.delegate=self;
    
    
    return cell;
}
//行的高度
- (CGFloat)tableView:(nonnull UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    return 350;
}
//节头
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return -30;
}
//点击时触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self performSegueWithIdentifier:@"showTime" sender:indexPath];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

-(void)headAction{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushSlideslip" object:nil];

}
//传值
- (void)prepareForSegue:(nonnull UIStoryboardSegue *)segue sender:(nullable id)sender{
  
    if ([segue.identifier isEqualToString:@"showTime"]) {
        
        MyLifeDetailsViewController * detailView = [segue destinationViewController];
        
        NSIndexPath * indexPath = sender;
        
        NSString * hImageName = self.headViews[indexPath.section];
        detailView.headViews = @[hImageName];
        
        NSString * middleImage =self.middleViews[indexPath.section];
        detailView.middleViews=@[middleImage];
        
        NSString * milldlImage2=self.middleView2s[indexPath.section];
        detailView.middleView2s=@[milldlImage2];
        
        NSString * commentImage=self.commentViews[indexPath.section];
        detailView.commentViews=@[commentImage];
        
        NSString * labelName = self.nameLabels[indexPath.section];
        detailView.nameLabels=@[labelName];
        
        NSString * labelTime = self.timeLabels[indexPath.section];
        detailView.timeLabels=@[labelTime];
        
        NSString * labelContent= self.contentLabels[indexPath.section];
        detailView.contentLabels=@[labelContent];
        
        NSString * labelZan = self.zanLabels[indexPath.section];
        detailView.zanLabels=@[labelZan];
        
        NSString * labelComment=self.commentLabels[indexPath.section];
        detailView.commentLabels=@[labelComment];
        
    }
    
}
-(void)zanLoveWithCell:(MyLifeTableViewCell *)cell{
    
    NSIndexPath * indexPath = [self.myTabelView indexPathForCell:cell];
    
    self.zanLabels[indexPath.section]=cell.zanLabel.text;
    
    
}
-(void)zanZanWithCell:(MyLifeTableViewCell *)cell{
    
    if (self.iszan) {
        self.iszan = NO;
        [cell.zanButton setImage:[UIImage imageNamed:@"iconfont-zan.png"] forState:UIControlStateNormal];

    }else{
        self.iszan = YES;
        [cell.zanButton setImage:[UIImage imageNamed:@"iconfont-zanz.png"] forState:UIControlStateNormal];

    
    }
    
    
}
-(void)tapAction{
    
    _tapView = [[UIView alloc]initWithFrame: CGRectMake(0, 0, 320, 568)];
    
    _tapView.backgroundColor = [UIColor blackColor];
    
    [self.navigationController.view addSubview:_tapView];
    

    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.clipsToBounds = YES;
    
    imageView.center = CGPointMake(160, 284);
    
    imageView.image = [UIImage imageNamed:self.middleViews[0]];
    
    [_tapView addSubview:imageView];
    
        
    
    //轻敲手势
    UITapGestureRecognizer * tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapViewAction)];
    
    //手指数量
    tap.numberOfTouchesRequired=1;
    
    //连击次数
    tap.numberOfTapsRequired=1;
    
    [_tapView addGestureRecognizer:tap];
    
    

    
}

-(void)tapViewAction{


    [_tapView removeFromSuperview];
    
}

-(void)tAction{
    
    _tapView2 =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    
    _tapView2.backgroundColor=[UIColor blackColor];
    
    [self.navigationController.view addSubview:_tapView2];
    
    
    UIImageView * imageView2 =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    
    imageView2.contentMode=UIViewContentModeScaleAspectFit;
    imageView2.clipsToBounds=YES;
    
    imageView2.center=CGPointMake(160, 284);
    
    imageView2.image=[UIImage imageNamed:self.middleView2s[0]];
    
    [_tapView2 addSubview:imageView2];
    
    
    //轻敲手势
    UITapGestureRecognizer * tap2 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tViewAction)];
    
    //手指数量
    tap2.numberOfTouchesRequired=1;
    
    //连击次数
    tap2.numberOfTapsRequired=1;
    
    [_tapView2 addGestureRecognizer:tap2];

    
    
}
-(void)tViewAction{
    
    [_tapView2 removeFromSuperview];
}
//写说说
-(void)tellAboutAction{

    
    [self performSegueWithIdentifier:@"tellAbout" sender:nil];
}
@end
